package com.swanclouds.redfish.account.domain.Oem.BMC.user;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.swanclouds.model.account.builder.BMC.BMCCreateAccount;
import com.swanclouds.model.account.builder.BMC.BMCCreateAccountBuilder;
import com.swanclouds.model.common.redfish.Oem;

/**
 * Oem.MBC 创建用户
 * @author 张立强
 * @version jdk1.8.0
 */
public class BMCCreateAccountContrete implements BMCCreateAccount {

    @JsonProperty("UserName")
    private String userName;

    @JsonProperty("Password")
    private String password;

    @JsonProperty("RoleId")
    private RoleId roleId;

    @JsonProperty("Locked")
    private Boolean locked;

    @JsonProperty("Enabled")
    private Boolean enabled;

    @JsonProperty("Oem")
    private Oem oem;
    /**
     * 用户名，大小写字母、数字、特殊符号“-”、“_”、“@”，字母开头
     *
     * @return UserName
     */
    @Override
    public String getUserName() {
        return this.userName;
    }

    /**
     * 用户密码，长度为8到16个字符串
     *
     * @return Password
     */
    @Override
    public String getPassword() {
        return this.password;
    }

    /**
     * 用户角色，可设置的角色
     * BMC [Administrator,Operator,User,None]
     * HuaWei [Operator,Commonuser,Noaccess,CustomRole1...]
     *
     * @return RoleId
     */
    @Override
    public String getRoleId() {
        return roleId != null ? roleId.name() : null;
    }

    /**
     * 用户锁定状态
     *
     * @return Locked [true: 锁定; false: 未锁定]
     */
    @Override
    public Boolean getLocked() {
        return this.locked;
    }

    /**
     * 用户使能状态
     *
     * @return Enabled [true: 能用; false: 禁用]
     */
    @Override
    public Boolean getEnabled() {
        return this.enabled;
    }

    /**
     * 自定义属性
     * "Oem":{
     * "BMC":{
     * "PasswordComplexityEnabled": password_complexity_enabled,
     * "PasswordValidityDays": password_validity_days，
     * "PasswordValidityRemindDays": password_validity_remind_days
     * }
     * }
     * PasswordComplexityEnabled: 是否开启密码复杂度。当未下发该参数时，默认为false，不进行密码复杂度校验。true，开启，进行密码校验false，不开启，不进行密码校验
     * PasswordValidityDays: 密码有效期，表示从用户创建开始，密码有效的天数。当未下发该参数，表示禁用密码有效期，此时密码一直有效
     * PasswordValidityRemindDays: 密码有效期提醒天数
     *
     * @return Map&lt;String, Object&gt; oem
     */
    @Override
    public Oem getOem() {
        return this.oem;
    }

    @Override
    public BMCCreateAccountBuilder toBuilder() {
        return new BMCCreateAccountConceteBuilder();
    }

    public static BMCCreateAccountBuilder builder() {
        return new BMCCreateAccountContrete().toBuilder();
    }
    public enum RoleId {
        Administrator,Operator,User,None;
    }

    public static class BMCCreateAccountConceteBuilder implements BMCCreateAccountBuilder {

        BMCCreateAccountContrete m;

        BMCCreateAccountConceteBuilder() {
            this(new BMCCreateAccountContrete());
        }

        BMCCreateAccountConceteBuilder(BMCCreateAccountContrete m) {
            this.m = m;
        }
        /**
         * 用户名赋值
         *
         * @param userName 用户名
         * @return BMCCreateAccountBuilder
         */
        @Override
        public BMCCreateAccountBuilder UserName(String userName) {
            m.userName = userName;
            return this;
        }

        /**
         * 用户密码赋值
         *
         * @param password 密码
         * @return BMCCreateAccountBuilder
         */
        @Override
        public BMCCreateAccountBuilder Password(String password) {
            m.password = password;
            return this;
        }

        /**
         * 用户角色赋值
         *
         * @param roleId 用户组
         * @return BMCCreateAccountBuilder
         */
        @Override
        public BMCCreateAccountBuilder RoleId(String roleId) {
            m.roleId = RoleId.valueOf(roleId);
            if (m.roleId == null) {
                m.roleId = RoleId.None;
            }
            return this;
        }

        /**
         * 用户锁定状态
         *
         * @param locked 锁定
         * @return BMCCreateAccountBuilder
         */
        @Override
        public BMCCreateAccountBuilder Locked(Boolean locked) {
            m.locked = locked;
            return this;
        }

        /**
         * 用户使能状态
         *
         * @param enabled 启用
         * @return BMCCreateAccountBuilder
         */
        @Override
        public BMCCreateAccountBuilder Enabled(Boolean enabled) {
            m.enabled = true;
            return this;
        }

        @Override
        public BMCCreateAccountBuilder Oem(Oem oem) {
            m.oem = oem;
            return this;
        }


        /**
         * Creates and return the Model Entity M
         *
         * @return M instance
         */
        @Override
        public BMCCreateAccount build() {
            return m;
        }

        /**
         * Creates a Builder using the param M as the default values
         *
         * @param in The Model M
         * @return Builder
         */
        @Override
        public BMCCreateAccountBuilder from(BMCCreateAccount in) {
            m = (BMCCreateAccountContrete) in;
            return this;
        }

        @Override
        public String toString() {
            ObjectMapper objectMapper = new ObjectMapper();
            try {
                return objectMapper.writeValueAsString(this);
            } catch (JsonProcessingException e) {
            }
            return "BMCCreateAccountConceteBuilder {" +
                    "m=" + m +
                    '}';
        }
    }

    @Override
    public String toString() {
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            return objectMapper.writeValueAsString(this);
        } catch (JsonProcessingException e) {
        }
        return "BMCCreateAccountContrete {" +
                "userName='" + userName + '\'' +
                ", password='" + password + '\'' +
                ", roleId=" + roleId +
                ", locked=" + locked +
                ", enabled=" + enabled +
                ", oem=" + oem +
                '}';
    }
}
